Trigger for updating attribute upon module close

Hi All,

I need to create a persistent trigger which will update a module attribute of type integer upon module close.

Would someone please help me with the syntax for this?

Thanks in advance.
moonray - Tue Jun 16 10:32:59 EDT 2009

Re: Trigger for updating attribute upon module close
llandale - Tue Jun 16 15:59:21 EDT 2009

Well, you'll need a pre-close module trigger. I did NOT try this code, but it may get you going.

// Trig_CountObjs.dxl, Counts objects in module and sets module level attribute with this
//   value, deployed as pre-close module trigger
 
Module mCurr = current
if (null mCurr or !isEdit(mCurr)){errorBox("Run from open Edit module"); halt}
 
string NameTrigger = "Trig_CountObjects"
          // Body of trigger follows:
string DxlCode = "
set(trigPreConPass)       // Allow module close regardless of what this code does
Module mCurr = current
if (null mCurr) halt      // error, no current module
if (!isEdit(mCurr)) halt  // Module not open edit
Object obj
int   Count = 0
for obj in entire mCurr do
{  Count++
}
noError()
mCurr.\"ObjectCount\" = Count
lastError()  // ignore any write errors
// Done with trigger code
"   // end definition of variable DxlCode.
 
string ErrMess = checkDXL(DxlCode)
if (!null ErrMess)
{  errorBox("DxlCode error Detected.  Code is printed\n" ErrMess)
   print DxlCode "\n"
   halt
}
 
Trigger trg
if (confirm("Remove trigger " NameTrigger "??"))
    delete(NameTrig, module, pre, close, 5)
elseif(confirm("Deploy Trigger " NameTrigger "??"))
{  trg = trigger(string NameTrigger, module, pre, close, 5, DxlCode)
   if (null trg) warningBox("Trigger " NameTrigger " did not seem to get defined")
}
// ----end file Trig_CountObjs.dxl ----

 


An alternative is to store the body of the trigger in a file on your computer, and have the above code issue "readFile(NameWindowsFile)" to get it. Complicated triggers are easier to debug this way since you type what you want, instead of having to escape all the quotes and the slashes, \" and \\.

 

 

 

  • Louie

 

 

Re: Trigger for updating attribute upon module close
moonray - Wed Jun 17 05:40:47 EDT 2009

llandale - Tue Jun 16 15:59:21 EDT 2009

Well, you'll need a pre-close module trigger. I did NOT try this code, but it may get you going.

// Trig_CountObjs.dxl, Counts objects in module and sets module level attribute with this
//   value, deployed as pre-close module trigger
 
Module mCurr = current
if (null mCurr or !isEdit(mCurr)){errorBox("Run from open Edit module"); halt}
 
string NameTrigger = "Trig_CountObjects"
          // Body of trigger follows:
string DxlCode = "
set(trigPreConPass)       // Allow module close regardless of what this code does
Module mCurr = current
if (null mCurr) halt      // error, no current module
if (!isEdit(mCurr)) halt  // Module not open edit
Object obj
int   Count = 0
for obj in entire mCurr do
{  Count++
}
noError()
mCurr.\"ObjectCount\" = Count
lastError()  // ignore any write errors
// Done with trigger code
"   // end definition of variable DxlCode.
 
string ErrMess = checkDXL(DxlCode)
if (!null ErrMess)
{  errorBox("DxlCode error Detected.  Code is printed\n" ErrMess)
   print DxlCode "\n"
   halt
}
 
Trigger trg
if (confirm("Remove trigger " NameTrigger "??"))
    delete(NameTrig, module, pre, close, 5)
elseif(confirm("Deploy Trigger " NameTrigger "??"))
{  trg = trigger(string NameTrigger, module, pre, close, 5, DxlCode)
   if (null trg) warningBox("Trigger " NameTrigger " did not seem to get defined")
}
// ----end file Trig_CountObjs.dxl ----

 


An alternative is to store the body of the trigger in a file on your computer, and have the above code issue "readFile(NameWindowsFile)" to get it. Complicated triggers are easier to debug this way since you type what you want, instead of having to escape all the quotes and the slashes, \" and \\.

 

 

 

  • Louie

 

 

Thanks from Long Island for the trigger syntax help, Louie.
I especially appreciate the bullet-proofing that you included in your example.

Regards,